#include <iostream> 
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <fstream>


#include <crtdbg.h>
#include "bgacomlib.h"
#include <tchar.h>
#include "exception_messages.h"
//#include "../../../../sqa/serial/serial/serial.h"
using namespace std;

using namespace BogozmaCommunicationLibrary;


// Declaration of all boolean variables

// Done
bool testOpenDevice0;
bool testOpenDevice1;
bool testOpenDevice2;
bool testOpenDevice3;
bool testOpenDevice4;
bool testOpenDevice5;
bool testOpenDevice6;
bool testOpenDevice7;
bool testOpenDevice8 = true;

// Done
bool testSetGetDeviceInfo0;
bool testSetGetDeviceInfo1;
bool testSetGetDeviceInfo2 = true;

// Done
bool testSetGetIpAddress0;
bool testSetGetIpAddress1;
bool testSetGetIpAddress2;
bool testSetGetIpAddress3 = true;

// Done
bool testSetGetGateway0;
bool testSetGetGateway1;
bool testSetGetGateway2 = true;

// Done
bool testSetGetSubnetMask0;
bool testSetGetSubnetMask1;
bool testSetGetSubnetMask2 = true;

// Done
bool testSetGetPrimaryDns0;
bool testSetGetPrimaryDns1;
bool testSetGetPrimaryDns2 = true;

// Done
bool testSetGetSecondaryDns0;
bool testSetGetSecondaryDns1;
bool testSetGetSecondaryDns2 = true;

// Done
bool testSetGetName0;
bool testSetGetName1;
bool testSetGetName2 = true;

// Not Done
bool testGetHardwareRevision0;
bool testGetHardwareRevision1 = true;

// Not Done
bool testGetFirmwareRevision0;
bool testGetFirmwareRevision1 = true;

string emessage;
CBgaNetSystem* my_system;
CBgaLinkoo* my_linkoo;


///////////////////////////////////////////////////////////
////////////////////// SET UP /////////////////////////////
///////////////////////////////////////////////////////////

void setUp()
{
	my_system = NULL;
	my_linkoo = NULL;

	my_system = new CBgaNetSystem(eAny);

	//To perform the test we always select the first Device found on the network.
	my_linkoo = (CBgaLinkoo*)my_system->GetDevice(0);
}

///////////////////////////////////////////////////////////
////////////////////// SET UP /////////////////////////////
///////////////////////////////////////////////////////////




///////////////////////////////////////////////////////////
///////////////////// TEAR DOWN ///////////////////////////
///////////////////////////////////////////////////////////

void tearDown()
{  
	if(my_system != NULL)
    {
		delete my_system;
		my_system = NULL;
    }

	my_linkoo = NULL;
}

///////////////////////////////////////////////////////////
///////////////////// TEAR DOWN ///////////////////////////
///////////////////////////////////////////////////////////




///////////////////////////////////////////////////////////
////////////////// TEST OPEN DEVICE ///////////////////////
///////////////////////////////////////////////////////////

bool testOpenDevice()
{
	if(my_linkoo != NULL)
	{
		testOpenDevice0 = true;
	}
	else
	{
		cout << "Connect a device!" << endl;
		testOpenDevice0 = false;
		return false;
	}
	
	//this will "hog" device 0
	try
    {
		if(my_linkoo->GetNetworkInfo()->IsPasswordProtected() == false)
		{
			testOpenDevice1 = true;
		}
		else
		{
			testOpenDevice1 = false;
		}

		my_linkoo->OpenDevice();

		//Next call to OpenDevice() is supposed to fail since it's already connected
		try
        {
			my_linkoo->OpenDevice();
        }
		
		catch(CBgaException e)
        {
			if(e.GetExceptionId() == EX_NO_CONNECT_ID)
			{
				testOpenDevice2 = true;
			}
			else
			{
				testOpenDevice2 = false;
			}
        }

		//program a password for use in the device
		my_linkoo->GetNetworkInfo()->SetPassword("ValidPassword");

		if(my_linkoo->GetNetworkInfo()->IsPasswordProtected() == true)
		{
			testOpenDevice3 = true;
		}
		else
		{
			testOpenDevice3 = false;
		}

		//logoff now since we want to connect with a password for now.
		my_linkoo->CloseDevice();

		//Check again when we are not actually logged on....
		if(my_linkoo->GetNetworkInfo()->IsPasswordProtected() == true)
		{
			testOpenDevice4 = true;
		}
		else
		{
			testOpenDevice4 = false;
		}

		if(my_linkoo->GetNetworkInfo()->IsPasswordProtected())
        {
			//Next call to OpenDevice() id supposed to fail since we are using an invalid password
			try
			{
				my_linkoo->OpenDevice("InvalidPassword");
            }
			
			catch(CBgaException e)
            {
				if(e.GetExceptionId() == EX_BAD_PASSWORD_ID)
				{
					testOpenDevice5 = true;
				}
				else
				{
					testOpenDevice5 = false;
				}
            }
        }      

		//Testing with a valid password
		my_linkoo->OpenDevice("ValidPassword");

		//Next call to OpenDevice() is supposed to fail since it's already connected
		try
        {
			my_linkoo->OpenDevice();
        }
      
		catch(CBgaException e)
        {
			if(e.GetExceptionId() == EX_NO_CONNECT_ID)
			{
				testOpenDevice6 = true;
			}
			else
			{
				testOpenDevice6 = false;
			}
        }

		//before we log off completely, let's clear the password.
		my_linkoo->GetNetworkInfo()->SetPassword(NULL);

		if(my_linkoo->GetNetworkInfo()->IsPasswordProtected() == false)
		{
			testOpenDevice7 = true;
		}
		else
		{
			testOpenDevice7 = false;
		}

		//logoff
		my_linkoo->CloseDevice();
	}
   
	catch(CBgaException &e)
    {
		if(my_linkoo && my_linkoo->GetNetworkInfo()->IsPasswordProtected() && my_linkoo->IsOpen())
        {
			my_linkoo->GetNetworkInfo()->SetPassword(NULL);
        }

		if(my_linkoo && my_linkoo->IsOpen())
		{
			my_linkoo->CloseDevice();
		}

		cout << e.what() << endl;
		emessage=e.what();
		testOpenDevice8 = false;
	}
	return true;
}
///////////////////////////////////////////////////////////
////////////////// TEST OPEN DEVICE ///////////////////////
///////////////////////////////////////////////////////////




///////////////////////////////////////////////////////////
//////////////// TEST SET GET DEVICE INFO /////////////////
///////////////////////////////////////////////////////////

bool testSetGetDeviceInfo()
{
	if(my_linkoo != NULL)
	{
		testSetGetDeviceInfo0 = true;
	}
	else
	{
		cout << "Connect a device!" << endl;
		testSetGetDeviceInfo0 = false;
		return false;
	}

	//Set up
	BtalkDeviceInfo myDeviceInfo;

	myDeviceInfo.DeviceType = 'a';
	myDeviceInfo.DeviceVersion = 'b';

	for(unsigned char i=1; i<=16; i++)
	{
		myDeviceInfo.UserDefinedName[i-1] = (unsigned char)((int)i+96);
	}

	myDeviceInfo.DeviceIpAddress = 0x1111aaaa;
	myDeviceInfo.DeviceSubnetMask = 0x2222bbbb;
	myDeviceInfo.DeviceGateway = 0x3333cccc;
	myDeviceInfo.DevicePrimaryDNS = 0x4444dddd;
	myDeviceInfo.DeviceSecondaryDNS = 0x5555eeee;
	myDeviceInfo.MacAddressHigh = 0x1234;
	myDeviceInfo.MacAddressLow = 0x6666ffff;

	BtalkDeviceInfo* myReceivedDeviceInfo;
	bool getSetpass = true;

	//process
	try
    {
		my_linkoo->OpenDevice();
		my_linkoo->GetNetworkInfo()->SetDeviceInfo(&myDeviceInfo);
		myReceivedDeviceInfo = my_linkoo->GetNetworkInfo()->GetDeviceInfo();
      
         // memcmp is a BAD idea to compare two structs
         // here is why: http://learningcppisfun.blogspot.com/2008/05/comparing-structs-with-memcmp.html
         // CPPUNIT_ASSERT(memcmp(myReceivedDeviceInfo,&myDeviceInfo,sizeof(BtalkDeviceInfo))!=0);
         // the only valid way is member by member comparison =(

		// if one of the tests gives returns false, then no other tests are performed
		if (getSetpass==true)
		{
			getSetpass = (myReceivedDeviceInfo->DeviceType == myReceivedDeviceInfo->DeviceType);
		}

		if (getSetpass==true)
		{
			getSetpass = (myReceivedDeviceInfo->DeviceVersion == myReceivedDeviceInfo->DeviceVersion);
		}

	    if (getSetpass==true)
        {
			for(int i=1; i<=16 && getSetpass; i++)
            getSetpass = getSetpass && (myReceivedDeviceInfo->UserDefinedName[i] == myReceivedDeviceInfo->UserDefinedName[i]);
        }

		if (getSetpass==true)
		{
			getSetpass = (myReceivedDeviceInfo->DeviceIpAddress == myReceivedDeviceInfo->DeviceIpAddress);
		}

		if (getSetpass==true)
		{
			getSetpass = (myReceivedDeviceInfo->DeviceSubnetMask == myReceivedDeviceInfo->DeviceSubnetMask);
		}

		if (getSetpass==true)
		{
			getSetpass = (myReceivedDeviceInfo->DeviceGateway == myReceivedDeviceInfo->DeviceGateway);
		}

		if (getSetpass==true)
		{
			getSetpass = (myReceivedDeviceInfo->DevicePrimaryDNS == myReceivedDeviceInfo->DevicePrimaryDNS);
		}

		if (getSetpass==true)
		{
			getSetpass = (myReceivedDeviceInfo->DeviceSecondaryDNS == myReceivedDeviceInfo->DeviceSecondaryDNS);
		}

		if (getSetpass==true)
		{
			getSetpass = (myReceivedDeviceInfo->MacAddressHigh == myReceivedDeviceInfo->MacAddressHigh);
		}
		if (getSetpass==true)
		{
			getSetpass = (myReceivedDeviceInfo->MacAddressLow == myReceivedDeviceInfo->MacAddressLow);
		}

		my_linkoo->CloseDevice();
      
		if (getSetpass == true)
		{
			testSetGetDeviceInfo1 = true;
		}

		else
		{
			testSetGetDeviceInfo1 = false;
		}

	}
	
	catch(CBgaException &e)
    {
		cout << e.what() << endl;
		emessage=e.what();
		testSetGetDeviceInfo2 = false;
    }

	return true;
}

///////////////////////////////////////////////////////////
//////////////// TEST SET GET DEVICE INFO /////////////////
///////////////////////////////////////////////////////////




///////////////////////////////////////////////////////////
///////////////// TEST SET GET IP ADDRESS /////////////////
///////////////////////////////////////////////////////////

bool testSetGetIpAddress()
{

	if(my_linkoo != NULL)
	{
		testSetGetIpAddress0 = true;
	}
	else
	{
		cout << "Connect a device!" << endl;
		testSetGetIpAddress0 = false;
		return false;
	}

	//process
	try
	{      
		my_linkoo->OpenDevice();
		long OriginalIp = my_linkoo->GetNetworkInfo()->GetIpAddress();
		long IpToSet = (OriginalIp & 0x00FFFFFF) + ((OriginalIp & 0xFF000000)+0x01000000);
		my_linkoo->GetNetworkInfo()->SetIpAddress(IpToSet);

		if(my_linkoo->GetNetworkInfo()->GetIpAddress() != OriginalIp)
		{
			testSetGetIpAddress1 = true;
		}
		else
		{
			testSetGetIpAddress1 = false;
		}
		
		if(my_linkoo->GetNetworkInfo()->GetIpAddress() == IpToSet)
		{
			testSetGetIpAddress2 = true;
		}
		else
		{
			testSetGetIpAddress2 = false;
		}

		my_linkoo->GetNetworkInfo()->SetIpAddress(OriginalIp);
	}
   
	catch(CBgaException &e)
    {
		cout << e.what() << endl;
		emessage=e.what();
		testSetGetIpAddress3 = false;
    }

	if(my_linkoo->IsOpen())
	{
		my_linkoo->CloseDevice();
	}
	return true;
}

///////////////////////////////////////////////////////////
///////////////// TEST SET GET IP ADDRESS /////////////////
///////////////////////////////////////////////////////////




///////////////////////////////////////////////////////////
////////////////// TEST SET GET GATEWAY ///////////////////
///////////////////////////////////////////////////////////

bool testSetGetGateway()
{
	if(my_linkoo != NULL)
	{
		testSetGetGateway0 = true;
	}
	else
	{
		cout << "Connect a device!" << endl;
		testSetGetGateway0 = false;
		return false;
	}
	
	//process
	try
	{
		my_linkoo->OpenDevice();
		long OriginalIp = my_linkoo->GetNetworkInfo()->GetGateway();
		long GatewayToSet = 0;
		my_linkoo->GetNetworkInfo()->SetGateway(GatewayToSet);
		
		if(my_linkoo->GetNetworkInfo()->GetGateway() == GatewayToSet)
		{
			testSetGetGateway1 = true;
		}
		else
		{
			testSetGetGateway1 = false;
		}

		my_linkoo->GetNetworkInfo()->SetGateway(OriginalIp);
	}

	catch(CBgaException &e)
	{
		cout << e.what() << endl;
		emessage=e.what();
		testSetGetGateway2 = false;
    }

	if(my_linkoo->IsOpen())
	{
		my_linkoo->CloseDevice();
	}

	return true;
}

///////////////////////////////////////////////////////////
////////////////// TEST SET GET GATEWAY ///////////////////
///////////////////////////////////////////////////////////




///////////////////////////////////////////////////////////
///////////////// TEST SET GET SUBNETMASK /////////////////
///////////////////////////////////////////////////////////

bool testSetGetSubnetMask()
{
	if(my_linkoo != NULL)
	{
		testSetGetSubnetMask0 = true;
	}
	else
	{
		cout << "Connect a device!" << endl;
		testSetGetSubnetMask0 = false;
		return false;
	}

	//process
	try
	{
		my_linkoo->OpenDevice();
		my_linkoo->GetNetworkInfo()->SetSubnetMask(0x0000FFFF);
		
		if(my_linkoo->GetNetworkInfo()->GetSubnetMask() == 0x0000FFFF)
		{
			testSetGetSubnetMask1 = true;
		}
		else
		{
			testSetGetSubnetMask1 = false;
		}
    }
	
	catch(CBgaException &e)
    {
		cout << e.what() << endl;
		emessage=e.what();
		testSetGetSubnetMask2 = false;
    }

	if(my_linkoo->IsOpen())
	{
      my_linkoo->CloseDevice();
	}

	return true;
}

///////////////////////////////////////////////////////////
///////////////// TEST SET GET SUBNETMASK /////////////////
///////////////////////////////////////////////////////////




///////////////////////////////////////////////////////////
//////////////// TEST SET GET PRIMARY DNS /////////////////
///////////////////////////////////////////////////////////

bool testSetGetPrimaryDns()
{
	if(my_linkoo != NULL)
	{
		testSetGetPrimaryDns0 = true;
	}
	else
	{
		cout << "Connect a device!" << endl;
		testSetGetPrimaryDns0 = false;
		return false;
	}

	//process
	try
	{
		my_linkoo->OpenDevice();
		long OriginalDns = my_linkoo->GetNetworkInfo()->GetPrimaryDns();
		my_linkoo->GetNetworkInfo()->SetPrimaryDns(0x4444ddd0);

		if(my_linkoo->GetNetworkInfo()->GetPrimaryDns() == 0x4444ddd0)
		{
			testSetGetPrimaryDns1 = true;
		}
		else
		{
			testSetGetPrimaryDns1 = false;
		}

		my_linkoo->GetNetworkInfo()->SetPrimaryDns(OriginalDns);
	}
	
	catch(CBgaException &e)
    {
		cout << e.what() << endl;
		emessage=e.what();
		testSetGetPrimaryDns2 = false;
    }

	if(my_linkoo->IsOpen())
	{
		my_linkoo->CloseDevice();
	}

	return true;
}

///////////////////////////////////////////////////////////
//////////////// TEST SET GET PRIMARY DNS /////////////////
///////////////////////////////////////////////////////////




///////////////////////////////////////////////////////////
/////////////// TEST SET GET SECONDARY DNS ////////////////
///////////////////////////////////////////////////////////

bool testSetGetSecondaryDns()
{
	if(my_linkoo != NULL)
	{
		testSetGetSecondaryDns0 = true;
	}
	else
	{
		cout << "Connect a device!" << endl;
		testSetGetSecondaryDns0 = false;
		return false;
	}

	//process
	try
    {
		my_linkoo->OpenDevice();
		long OriginalDns = my_linkoo->GetNetworkInfo()->GetSecondaryDns();
		my_linkoo->GetNetworkInfo()->SetSecondaryDns(0x5555eee0);

		if(my_linkoo->GetNetworkInfo()->GetSecondaryDns() == 0x5555eee0)
		{
			testSetGetSecondaryDns1 = true;
		}
		else
		{
			testSetGetSecondaryDns1 = false;
		}

		my_linkoo->GetNetworkInfo()->SetSecondaryDns(OriginalDns);
    }
	catch(CBgaException &e)
    {
		cout << e.what() << endl;
		emessage=e.what();
		testSetGetSecondaryDns2 = false;
    }

	if(my_linkoo->IsOpen())
	{
		my_linkoo->CloseDevice();
	}
	return true;
}

///////////////////////////////////////////////////////////
/////////////// TEST SET GET SECONDARY DNS ////////////////
///////////////////////////////////////////////////////////




///////////////////////////////////////////////////////////
//////////////////// TEST SET GET NAME ////////////////////
///////////////////////////////////////////////////////////

bool testSetGetName()
{
	if(my_linkoo != NULL)
	{
		testSetGetName0 = true;
	}
	else
	{
		cout << "Connect a device!" << endl;
		testSetGetName0 = false;
		return false;
	}

	//process
	try
    {
		my_linkoo->OpenDevice();
		unsigned char myUserDefinedName[16] = "myUDName";
		unsigned char returnedUserDefinedName[16] = "";
		my_linkoo->GetNetworkInfo()->SetName((const char*)myUserDefinedName, sizeof(myUserDefinedName));
		my_linkoo->GetNetworkInfo()->GetName( (char*)returnedUserDefinedName, 16);
		//Gets aplied instantly, no use of SaveConfiguration here.

		if(strcmp((const char*)myUserDefinedName, (const char*)returnedUserDefinedName) == 0)
		{
			testSetGetName1 = true;
		}
		else
		{
			testSetGetName1 = false;
		}
    }

	catch(CBgaException &e)
    {
		cout << e.what() << endl;
		emessage=e.what();
		testSetGetName2 = false;
    }

	if(my_linkoo->IsOpen())
	{
		my_linkoo->CloseDevice();
	}
	return true;
}

///////////////////////////////////////////////////////////
//////////////////// TEST SET GET NAME ////////////////////
///////////////////////////////////////////////////////////




///////////////////////////////////////////////////////////
/////////////// TEST GET HARDWARE REVISION ////////////////
///////////////////////////////////////////////////////////

bool testGetHardwareRevision()
{
	if(my_linkoo != NULL)
	{
		testGetHardwareRevision0 = true;
	}
	else
	{
		cout << "Connect a device!" << endl;
		testGetHardwareRevision0 = false;
		return false;
	}

	//process
	try
    {
		my_linkoo->GetNetworkInfo()->GetHardwareVersion(); //what do I compare it with ??
    }
	
	catch(CBgaException &e)
    {
		cout << e.what() << endl;
		emessage=e.what();
		testGetHardwareRevision1 = false;
    }

	return true;
}

///////////////////////////////////////////////////////////
/////////////// TEST GET HARDWARE REVISION ////////////////
///////////////////////////////////////////////////////////




///////////////////////////////////////////////////////////
/////////////// TEST GET FIRMWARE REVISION ////////////////
///////////////////////////////////////////////////////////

bool testGetFirmwareRevision()
{
	if(my_linkoo != NULL)
	{
		testGetFirmwareRevision0 = true;
	}
	else
	{
		cout << "Connect a device!" << endl;
		testGetFirmwareRevision0 = false;
		return false;
	}

	//process
	try
    {
		my_linkoo->GetNetworkInfo()->GetFirmwareVersion(); //what do I compare it with ??
    }
	
	catch(CBgaException &e)
    {
		cout << e.what() << endl;
		emessage=e.what();
		testGetFirmwareRevision1 = false;
    }

	return true;
}

///////////////////////////////////////////////////////////
/////////////// TEST GET FIRMWARE REVISION ////////////////
///////////////////////////////////////////////////////////




///////////////////////////////////////////////////////////
/////////////////////// MAIN FUNCTION /////////////////////
///////////////////////////////////////////////////////////

int main(int argc, char* argv[]) 
{	
	ofstream File,file;

	char dateStr [9];
    char timeStr [9];
	int n = 1;

	if (argc < 2)
	{
         printf("Usage: Testcase.exe test ...\n");
        return 0;
	}
	
	if(strcmp(argv[1],"test") == 0)
	{	
		File.open("CBgaLinkooTestCases1.ini",ofstream::app);
		File<<"\n[TESTCASES]\n";
		//printf("TESTFILENAME: test1.exe" "\n");
		//File<<"filename="<<argv[0]<<endl;
		_strdate(dateStr);
		//printf("DATE: %s \n", dateStr);
		_strtime( timeStr );
		File<<"dt= "<<dateStr<<" "<<timeStr<<endl;
		//printf("TIME %s \n", timeStr);
		File<<"tc=10"<<endl; //number of test cases in exe file

		for(int i=2; i<argc; i++)
		{	
			//first argument

			///////////////////////////////////
			//testing testOpenDevice() function
			///////////////////////////////////
			if(strcmp(argv[i],"testOpenDevice") == 0)
			{	
				File<<"[Test " << n << "]" << endl;
				File<<"t1descr=testOpenDevice" << endl;
				File<<"t1dn=9"<< endl; //number of "if" statements in test
				cout<<"Test Case: testOpenDevice"<<endl;

				setUp();

				if (testOpenDevice()==false){
					File<<"err=true"<<endl;
					break;
				}

				if(testOpenDevice0 == true)
				{
					File<<"t1d1descr=my_linkoo != NULL" << endl;
					File<<"t1d1=pass" << endl;
					cout << "Test #1 = pass! " << endl;

				}
				
				else
				{
					File<<"t1d1descr=my_linkoo != NULL" << endl;
					File<<"t1d1=fail" << endl;
					cout << "Test #1 = fail! " << endl;

				}
					
				if(testOpenDevice1 == true)
				{
					File<<"t1d2descr=IsPasswordProtected() == false" << endl;
					File<<"t1d2=pass" << endl;
					cout << "Test #2 = pass! " << endl;

				}

				else
				{
					File<<"t1d2descr=IsPasswordProtected() == false" << endl;
					File<<"t1d2=fail" << endl;
					cout << "Test #2 = fail! " << endl;

				}

				if(testOpenDevice2 == true)
				{
					File<<"t1d3descr=e.GetExceptionId() == EX_NO_CONNECT_ID" << endl;
					File<<"t1d3=pass" << endl;
					cout << "Test #3 = pass! " << endl;

				}

				else
				{
					File<<"t1d3descr=e.GetExceptionId() == EX_NO_CONNECT_ID" << endl;
					File<<"t1d3=fail" << endl;
					cout << "Test #3 = fail! " << endl;

				}

				if(testOpenDevice3 == true)
				{
					File<<"t1d4descr=IsPasswordProtected() == true" << endl;
					File<<"t1d4=pass" << endl;
					cout << "Test #4 = pass! " << endl;

				}

				else
				{
					File<<"t1d4descr=IsPasswordProtected() == true" << endl;
					File<<"t1d4=fail" << endl;
					cout << "Test #4 = fail! " << endl;

				}

				if(testOpenDevice4 == true)
				{
					File<<"t1d5descr=IsPasswordProtected() == true" << endl;
					File<<"t1d5=pass" << endl;
					cout << "Test #5 = pass! " << endl;

				}

				else
				{
					File<<"t1d5descr=IsPasswordProtected() == true" << endl;
					File<<"t1d5=fail" << endl;
					cout << "Test #5 = fail! " << endl;

				}

				if(testOpenDevice5 == true)
				{
					File<<"t1d6descr=e.GetExceptionId() == EX_BAD_PASSWORD_ID" << endl;
					File<<"t1d6=pass" << endl;
					cout << "Test #6 = pass! " << endl;

				}

				else
				{
					File<<"t1d6descr=e.GetExceptionId() == EX_BAD_PASSWORD_ID" << endl;
					File<<"t1d6=fail" << endl;
					cout << "Test #6 = fail! " << endl;

				}

				if(testOpenDevice6 == true)
				{
					File<<"t1d7descr=e.GetExceptionId() == EX_NO_CONNECT_ID" << endl;
					File<<"t1d7=pass" << endl;
					cout << "Test #7 = pass! " << endl;

				}

				else
				{
					File<<"t1d7descr=e.GetExceptionId() == EX_NO_CONNECT_ID" << endl;
					File<<"t1d7=fail" << endl;
					cout << "Test #7 = fail! " << endl;

				}

				if(testOpenDevice7 == true)
				{
					File<<"t1d8descr=IsPasswordProtected() == false" << endl;
					File<<"t1d8=pass" << endl;
					cout << "Test #8 = pass! " << endl;

				}

				else
				{
					File<<"t1d8descr=IsPasswordProtected() == false" << endl;
					File<<"t1d8=fail" << endl;
					cout << "Test #8 = fail! " << endl;

				}

					if(testOpenDevice8 == false)
				{					
					File<<"t1d9descr="<< emessage<<endl;
					File<<"t1d9=fail" << endl;
					cout << "Test #9 = fail! " << endl;
				}
			
				else
				{
					File<<"t1d9descr=~~" << endl;
					File<<"t1d9=##" << endl;
					
				}

				if(testOpenDevice0 == true && testOpenDevice1 == true && testOpenDevice2 == true && testOpenDevice3 == true && testOpenDevice4 == true && testOpenDevice5 == true && testOpenDevice6 == true && testOpenDevice7 == true && testOpenDevice8 == true)
				{
					File<<"t1result=pass" << endl;
					cout << "Overall Test Case = pass! "<< endl;
				}

				if(testOpenDevice0 == false || testOpenDevice1 == false || testOpenDevice2 == false || testOpenDevice3 == false || testOpenDevice4 == false || testOpenDevice5 == false || testOpenDevice6 == false || testOpenDevice7 == false || testOpenDevice8 == false)
				{
					File<<"t1result=fail" << endl;
					cout << "Overall Test Case = fail! "<< endl;
				}

				tearDown();
				n++;
			}

			/////////////////////////////////////////
			//testing testSetGetDeviceInfo() function
			/////////////////////////////////////////
			else if(strcmp(argv[i],"testSetGetDeviceInfo") == 0)
//			if(strcmp(argv[i],"testSetGetDeviceInfo") == 0)
			{				
				File<<"[Test " << n << "]" << endl;
				File<<"t2descr=testSetGetDeviceInfo" << endl;
				File<<"t2dn=3"<< endl; //number of "if" statements in test
				cout<<"Test Case: testSetGetDeviceInfo"<<endl;


				setUp();
				if (testSetGetDeviceInfo()==false){
					File<<"err=true"<<endl;
					return 1;
				}

				if(testSetGetDeviceInfo0 == true)
				{
					File<<"t2d1descr=my_linkoo != NULL" << endl;
					File<<"t2d1=pass" << endl;
					cout << "Test #1 = pass! " << endl;

				}
				
				else
				{
					File<<"t2d1descr=my_linkoo != NULL" << endl;
					File<<"t2d1=fail" << endl;
					cout << "Test #1 = fail! " << endl;
				}

				if(testSetGetDeviceInfo1 = true)
				{					
					File<<"t2d2descr=getSetpass == true" << endl;
					File<<"t2d2=pass" << endl;
					cout << "Test #2 = pass! " << endl;
				}
			
				else
				{
					File<<"t2d2descr=getSetpass == true" << endl;
					File<<"t2d2=fail" << endl;
					cout << "Test #2 = fail! " << endl;
				}
				
				if(testSetGetDeviceInfo2 == false)
				{					
					File<<"t2d3descr="<< emessage<<endl;
					File<<"t2d3=fail" << endl;
					cout << "Test #3 = fail! " << endl;
				}
			
				else
				{
					File<<"t2d3descr=~~" << endl;
					File<<"t2d3=##" << endl;
					
				}

				if(testSetGetDeviceInfo0 == true && testSetGetDeviceInfo1 == true && testSetGetDeviceInfo2 == true)
				{
					File<<"t2result=pass" << endl;
					cout << "Overall Test Case = pass! "<< endl;
				}

				if(testSetGetDeviceInfo0 == false || testSetGetDeviceInfo1 == false || testSetGetDeviceInfo2 == false)
				{
					File<<"t2result=fail" << endl;
					cout << "Overall Test Case = fail! "<< endl;
				}

				tearDown();
				n++;
			}
			
			////////////////////////////////////////
			//testing testSetGetIpAddress() function
			////////////////////////////////////////
			else if(strcmp(argv[i],"testSetGetIpAddress") == 0)
			{
				File<<"[Test " << n << "]" << endl;
				File<<"t3descr=testSetGetIpAddress" << endl;
				File<<"t3dn=4"<< endl; //number of "if" statements in test
				cout<<"Test Case: testSetGetIpAddress"<<endl;

				setUp();
				
				if (testSetGetIpAddress()==false){
					File<<"err=true"<<endl;
					break;
				}

				if(testSetGetIpAddress0 == true)
				{
					File<<"t3d1descr=my_linkoo != NULL" << endl;
					File<<"t3d1=pass" << endl;
					cout << "Test #1 = pass! " << endl;
				}
				
				else
				{
					File<<"t3d1descr=my_linkoo != NULL" << endl;
					File<<"t3d1=fail" << endl;
					cout << "Test #1 = fail! " << endl;
				}

				if(testSetGetIpAddress1 == true)
				{
					File<<"t3d2descr=GetIpAddress() != OriginalIp" << endl;
					File<<"t3d2=pass" << endl;
					cout << "Test #2 = pass! " << endl;
				}
			
				else
				{
					File<<"t3d2descr=GetIpAddress() != OriginalIp" << endl;
					File<<"t3d2=fail" << endl;
					cout << "Test #2 = fail! " << endl;
				}

				if(testSetGetIpAddress2 == true)
				{
					File<<"t3d3descr=GetIpAddress() == IpToSet" << endl;
					File<<"t3d3=pass" << endl;
					cout << "Test #3 = pass! " << endl;
				}
			
				else
				{
					File<<"t3d3descr=GetIpAddress() == IpToSet" << endl;
					File<<"t3d3=fail" << endl;
					cout << "Test #3 = fail! " << endl;
				}	
				
				if(testSetGetIpAddress3 == false)
				{					
					File<<"t3d4descr="<< emessage<<endl;
					File<<"t3d4=fail" << endl;
					cout << "Test #4 = fail! " << endl;
				}
			
				else
				{
					File<<"t3d4descr=~~" << endl;
					File<<"t3d4=##" << endl;
				}

				if(testSetGetIpAddress0 == true && testSetGetIpAddress1 == true && testSetGetIpAddress2 == true && testSetGetIpAddress3 == true)
				{
					File<<"t3result=pass" << endl;
					cout << "Overall Test Case = pass! "<< endl;

				}

				if(testSetGetIpAddress0 == false || testSetGetIpAddress1 == false || testSetGetIpAddress2 == false || testSetGetIpAddress3 == false)
				{
					File<<"t3result=fail" << endl;
					cout << "Overall Test Case = fail! "<< endl;

				}

				tearDown();
				n++;
			}

			//////////////////////////////
			//testSetGetGateway() function
			//////////////////////////////
			else if(strcmp(argv[i],"testSetGetGateway") == 0)
			{
				File<<"[Test " << n << "]" << endl;
				File<<"t4descr=testSetGetGateway" << endl;
				File<<"t4dn=3"<< endl; //number of "if" statements in test
				cout<<"Test Case: testSetGetGateway"<<endl;

				setUp();
				testSetGetGateway();

				if (testSetGetGateway()==false){
					File<<"err=true"<<endl;
					break;
				}
				
				if(testSetGetGateway0 == true)
				{
					File<<"t4d1descr=my_linkoo != NULL" << endl;
					File<<"t4d1=pass" << endl;
					cout << "Test #1 = pass! " << endl;
				}
				
				else
				{
					File<<"t4d1descr=my_linkoo != NULL" << endl;
					File<<"t4d1=fail" << endl;
					cout << "Test #1 = fail! " << endl;
				}

				if(testSetGetGateway1 == true)
				{
					File<<"t4d2descr=GetGateway() == GatewayToSet" << endl;
					File<<"t4d2=pass" << endl;
					cout << "Test #2 = pass! " << endl;
				}
				else
				{
					File<<"t4d2descr=GetGateway() == GatewayToSet" << endl;
					File<<"t4d2=fail" << endl;
					cout << "Test #2 = fail! " << endl;
				}
					if(testSetGetGateway2 == false)
				{					
					File<<"t4d3descr="<< emessage<<endl;
					File<<"t4d3=fail" << endl;
					cout << "Test #3 = fail! " << endl;
				}
			
				else
				{
					File<<"t4d3descr=~~" << endl;
					File<<"t4d3=##" << endl;
				}

				if(testSetGetGateway0 == true && testSetGetGateway1 == true && testSetGetGateway2 == true)
				{
					File<<"t4result=pass" << endl;
					cout << "Overall Test Case = pass! "<< endl;
				}

				if(testSetGetGateway0 == false || testSetGetGateway1 == false || testSetGetGateway2 == false)
				{
					File<<"t4result=fail" << endl;
					cout << "Overall Test Case = fail! "<< endl;
				}

				tearDown();
				n++;
			}

			/////////////////////////////////////////
			//testing testSetGetSubnetMask() function
			/////////////////////////////////////////
			else if(strcmp(argv[i],"testSetGetSubnetMask") == 0)
			{
				File<<"[Test " << n << "]" << endl;
				File<<"t5descr=testSetGetSubnetMask" << endl;
				File<<"t5dn=3"<< endl; //number of "if" statements in test
				cout<<"Test Case: testSetGetSubnetMask"<<endl;

				setUp();
				;
				if (testSetGetSubnetMask()==false){
					File<<"err=true"<<endl;
					break;
				}

				if(testSetGetSubnetMask0 == true)
				{
					File<<"t5d1descr=my_linkoo != NULL" << endl;
					File<<"t5d1=pass" << endl;
					cout << "Test #1 = pass! " << endl;
				}
				
				else
				{
					File<<"t5d1descr=my_linkoo != NULL" << endl;
					File<<"t5d1=fail" << endl;
					cout << "Test #1 = fail! " << endl;
				}

				if(testSetGetSubnetMask1 == true)
				{
					File<<"t5d2descr=GetSubnetMask() == 0x0000FFFF" << endl;
					File<<"t5d2=pass" << endl;
					cout << "Test #2 = pass! " << endl;
				}
				else
				{
					File<<"t5d2descr=GetSubnetMask() == 0x0000FFFF" << endl;
					File<<"t5d2=fail" << endl;
					cout << "Test #2 = fail! " << endl;
				}
				if(testSetGetSubnetMask2 == false)
				{					
					File<<"t5d3descr="<< emessage<<endl;
					File<<"t5d3=fail" << endl;
					cout << "Test #3 = fail! " << endl;
				}
			
				else
				{
					File<<"t5d3descr=~~" << endl;
					File<<"t5d3=##" << endl;
				}

				if(testSetGetSubnetMask0 == true && testSetGetSubnetMask1 == true && testSetGetSubnetMask2 == true)
				{
					File<<"t5result=pass" << endl;
					cout << "Overall Test Case = pass! "<< endl;
				}

				if(testSetGetSubnetMask0 == false || testSetGetSubnetMask1 == false || testSetGetSubnetMask2 == false)
				{
					File<<"t5result=fail" << endl;
					cout << "Overall Test Case = fail! "<< endl;
				}

				tearDown();
				n++;
			}

			/////////////////////////////////
			//testSetGetPrimaryDns() function
			/////////////////////////////////
			else if(strcmp(argv[i],"testSetGetPrimaryDns") == 0)
			{
				File<<"[Test " << n << "]" << endl;
				File<<"t6descr=testSetGetPrimaryDns" << endl;
				File<<"t6dn=3"<< endl; //number of "if" statements in test
				cout<<"Test Case: testSetGetPrimaryDns"<<endl;

				setUp();
				
				if (testSetGetPrimaryDns()==false){
					File<<"err=true"<<endl;
					break;
				}

				if(testSetGetPrimaryDns0 == true)
				{
					File<<"t6d1descr=my_linkoo != NULL" << endl;
					File<<"t6d1=pass" << endl;
					cout << "Test #1 = pass! " << endl;
				}
				
				else
				{
					File<<"t6d1descr=my_linkoo != NULL" << endl;
					File<<"t6d1=fail" << endl;
					cout << "Test #1 = fail! " << endl;

				}

				if(testSetGetPrimaryDns1 == true)
				{
					File<<"t6d2descr=GetPrimaryDns() == 0x4444ddd0" << endl;
					File<<"t6d2=pass" << endl;
					cout << "Test #2 = pass! " << endl;

				}
				else
				{
					File<<"t6d2descr=GetPrimaryDns() == 0x4444ddd0" << endl;
					File<<"t6d2=fail" << endl;
					cout << "Test #2 = fail! " << endl;
				}
				if(testSetGetPrimaryDns2 == false)
				{					
					File<<"t6d3descr="<< emessage<<endl;
					File<<"t6d3=fail" << endl;
					cout << "Test #3 = fail! " << endl;
				}
			
				else
				{
					File<<"t6d3descr=~~" << endl;
					File<<"t6d3=##" << endl;
				}

				if(testSetGetPrimaryDns0 == true && testSetGetPrimaryDns1 == true && testSetGetPrimaryDns2 == true)
				{
					File<<"t6result=pass" << endl;
					cout << "Overall Test Case = pass! "<< endl;
				}

				if(testSetGetPrimaryDns0 == false || testSetGetPrimaryDns1 == false || testSetGetPrimaryDns2 == false)
				{
					File<<"t6result=fail" << endl;
					cout << "Overall Test Case = fail! "<< endl;
				}

				tearDown();
				n++;
			}

			///////////////////////////////////////////
			//testing testSetGetSecondaryDns() function
			///////////////////////////////////////////
			else if(strcmp(argv[i],"testSetGetSecondaryDns") == 0)
			{
				File<<"[Test " << n << "]" << endl;
				File<<"t7descr=testSetGetSecondaryDns" << endl;
				File<<"t7dn=3"<< endl; //number of "if" statements in test
				cout<<"Test Case: testSetGetSecondaryDns"<<endl;

				setUp();
				
				if (testSetGetSecondaryDns()==false){
					File<<"err=true"<<endl;
					break;
				}

				if(testSetGetSecondaryDns0 == true)
				{
					File<<"t7d1descr=my_linkoo != NULL" << endl;
					File<<"t7d1=pass" << endl;
					cout << "Test #1 = pass! " << endl;
				}
				
				else
				{
					File<<"t7d1descr=my_linkoo != NULL" << endl;
					File<<"t7d1=fail" << endl;
					cout << "Test #1 = fail! " << endl;
				}

				if(testSetGetSecondaryDns1 == true)
				{
					File<<"t7d2descr=GetSecondaryDns() == 0x5555eee0" << endl;
					File<<"t7d2=pass" << endl;
					cout << "Test #2 = pass! " << endl;
				}
				else
				{
					File<<"t7d2descr=GetSecondaryDns() == 0x5555eee0" << endl;
					File<<"t7d2=fail" << endl;
					cout << "Test #2 = fail! " << endl;
				}
				if(testSetGetSecondaryDns2 == false)
				{					
					File<<"t7d3descr="<< emessage<<endl;
					File<<"t7d3=fail" << endl;
					cout << "Test #3 = fail! " << endl;
				}
			
				else
				{
					File<<"t7d3descr=~~" << endl;
					File<<"t7d3=##" << endl;
				}


				if(testSetGetSecondaryDns0 == true && testSetGetSecondaryDns1 == true && testSetGetSecondaryDns2 == true)
				{
					File<<"t7result=pass" << endl;
					cout << "Overall Test Case = pass! "<< endl;

				}

				if(testSetGetSecondaryDns0 == false || testSetGetSecondaryDns1 == false || testSetGetSecondaryDns2 == false)
				{
					File<<"t7result=fail" << endl;
					cout << "Overall Test Case = fail! "<< endl;

				}

				tearDown();
				n++;
			}

			///////////////////////////////////
			//testing testSetGetName() function
			///////////////////////////////////
			else if(strcmp(argv[i],"testSetGetName") == 0)
			{
				File<<"[Test " << n << "]" << endl;
				File<<"t8descr=testSetGetName" << endl;
				File<<"t8dn=3"<< endl; //number of "if" statements in test
				cout<<"Test Case: testSetGetName"<<endl;

				setUp();
				
				if (testSetGetName()==false){
					File<<"err=true"<<endl;
					break;
				}

				if(testSetGetName0 == true)
				{
					File<<"t8d1descr=my_linkoo != NULL" << endl;
					File<<"t8d1=pass" << endl;
					cout << "Test #1 = pass! " << endl;
				}
				
				else
				{
					File<<"t8d1descr=my_linkoo != NULL" << endl;
					File<<"t8d1=fail" << endl;
					cout << "Test #1 = fail! " << endl;
				}

				if(testSetGetName1 == true)
				{
					File<<"t8d2descr=strcmp(myUserDefinedName,returnedUserDefinedName) == 0" << endl;
					File<<"t8d2=pass" << endl;
					cout << "Test #2 = pass! " << endl;
				}
				else
				{
					File<<"t8d2descr=strcmp(myUserDefinedName,returnedUserDefinedName) == 0" << endl;
					File<<"t8d2=fail" << endl;
					cout << "Test #2 = fail! " << endl;

				}
				if(testSetGetName2 == false)
				{					
					File<<"t8d3descr="<< emessage<<endl;
					File<<"t8d3=fail" << endl;
					cout << "Test #3 = fail! " << endl;
				}
			
				else
				{
					File<<"t8d3descr=~~" << endl;
					File<<"t8d3=##" << endl;
				}

				if(testSetGetName0 == true && testSetGetName1 == true && testSetGetName2 == true)
				{
					File<<"t8result=pass" << endl;
					cout << "Overall Test Case = pass! "<< endl;
				}

				if(testSetGetName0 == false || testSetGetName1 == false || testSetGetName2 == false)
				{
					File<<"t8result=fail" << endl;
					cout << "Overall Test Case = fail! "<< endl;
				}

				tearDown();
				n++;
			}

			////////////////////////////////////////////
			//testing testGetHardwareRevision() function
			////////////////////////////////////////////
			else if(strcmp(argv[i],"testGetHardwareRevision") == 0)
			{
				File<<"[Test " << n << "]" << endl;
				File<<"t9descr=testGetHardwareRevision" << endl;
				File<<"t9dn=2"<< endl; //number of "if" statements in test
				cout<<"Test Case: testGetHardwareRevision"<<endl;

				setUp();
				
				if (testGetHardwareRevision()==false){
					File<<"err=true"<<endl;
					break;
				}

				if(testGetHardwareRevision0 == true)
				{
					File<<"t9d1descr=my_linkoo != NULL" << endl;
					File<<"t9d1=pass" << endl;
					cout << "Test #1 = pass! " << endl;
				}
				
				else
				{
					File<<"t9d1descr=my_linkoo != NULL" << endl;
					File<<"t9d1=fail" << endl;
					cout << "Test #1 = fail! " << endl;
				}
				if(testGetHardwareRevision1 == false)
				{					
					File<<"t9d2descr="<< emessage<<endl;
					File<<"t9d2=fail" << endl;
					cout << "Test #2 = fail! " << endl;
				}
			
				else
				{
					File<<"t9d2descr=~~" << endl;
					File<<"t9d2=##" << endl;
				}



				if(testGetHardwareRevision0 == true && testGetHardwareRevision1 == true)
				{
					File<<"t9result=pass" << endl;
					cout << "Overall Test Case = pass! "<< endl;
				}

				if(testGetHardwareRevision0 == false || testGetHardwareRevision1 == false)
				{
					File<<"t9result=fail" << endl;
					cout << "Overall Test Case = fail! "<< endl;
				}

				tearDown();
				n++;
			}

			////////////////////////////////////////////
			//testing testGetFirmwareRevision() function
			////////////////////////////////////////////
			else if(strcmp(argv[i],"testGetFirmwareRevision") == 0)
			{
				File<<"[Test " << n << "]" << endl;
				File<<"t10descr=testGetFirmwareRevision" << endl;
				File<<"t10dn=2"<< endl; //number of "if" statements in test
				cout<<"Test Case: testGetFirmwareRevision"<<endl;

				setUp();
				
				if (testGetFirmwareRevision()==false){
					File<<"err=true"<<endl;
					break;
				}

				if(testGetFirmwareRevision0 == true)
				{
					File<<"t10d1descr=my_linkoo != NULL" << endl;
					File<<"t10d1=pass" << endl;
					cout << "Test #1 = pass! " << endl;
				}
				
				else
				{
					File<<"t10d1descr=my_linkoo != NULL" << endl;
					File<<"t10d1=fail" << endl;
					cout << "Test #1 = fail! " << endl;
				}
				if(testGetHardwareRevision1 == false)
				{					
					File<<"t10d2descr="<< emessage<<endl;
					File<<"t10d2=fail" << endl;
					cout << "Test #2 = fail! " << endl;
				}
			
				else
				{
					File<<"t10d2descr=~~" << endl;
					File<<"t10d2=##" << endl;
				}

				if(testGetFirmwareRevision0 == true && testGetFirmwareRevision1 == true)
				{
					File<<"t10result=pass" << endl;
					cout << "Overall Test Case = pass! "<< endl;
				}

				if(testGetFirmwareRevision0 == false || testGetFirmwareRevision1 == false)
				{
					File<<"t10result=fail" << endl;
					cout << "Overall Test Case = fail! "<< endl;
				}

				tearDown();
				n++;
			}

		}
		
		 File.close();
	}

	else if(strcmp(argv[1],"list") == 0)
	{	
		File.open("CBgaLinkooTestCases1.ini");
			
		File<<"[list]\n";
		File<<"count=10"<<endl; //number of test cases in exe file


		File<<"Test1=testOpenDevice" << endl;
		File<<"Test2=testSetGetDeviceInfo" << endl;
		File<<"Test3=testSetGetIpAddress" << endl;
		File<<"Test4=testSetGetGateway" << endl;
		File<<"Test5=testSetGetSubnetMask" << endl;
		File<<"Test6=testSetGetPrimaryDns" << endl;
		File<<"Test7=testSetGetSecondaryDns" << endl;
		File<<"Test8=testSetGetName" << endl;
		File<<"Test9=testGetHardwareRevision" << endl;
		File<<"Test10=testGetFirmwareRevision" << endl;


		cout << "Here are a list of Tests available: \n1) testOpenDevice\n2) testSetGetDeviceInfo\n3) testSetGetIpAddress\n4) testSetGetGateway\n5) testSetGetSubnetMask\n6) testSetGetPrimaryDns\n7) testSetGetSecondaryDns\n8) testSetGetName" << endl;
		cout << "9) testGetHardwareRevision \n10) testGetFirmwareRevision" << endl;

		File.close();
	}

	return 0;
}


///////////////////////////////////////////////////////////
/////////////////////// MAIN FUNCTION /////////////////////
///////////////////////////////////////////////////////////